# -*- makefile -*-

# Used by various components.  These rules need to precede them.
script/lexer.c_DEPENDENCIES = grub_script.tab.h

sbin_UTILITIES += grub-mkdevicemap
grub_mkdevicemap_SOURCES = gnulib/progname.c util/grub-mkdevicemap.c \
	util/deviceiter.c \
	util/misc.c

ifeq ($(target_cpu)-$(platform), sparc64-ieee1275)
grub_mkdevicemap_SOURCES += util/ieee1275/ofpath.c util/ieee1275/devicemap.c
else
grub_mkdevicemap_SOURCES += util/devicemap.c
endif

# For grub-mkelfimage.
bin_UTILITIES += grub-mkelfimage
grub_mkelfimage_SOURCES = gnulib/progname.c util/elf/grub-mkimage.c \
	util/misc.c util/resolve.c util/obj.c kern/list.c
util/elf/grub-mkimage.c_DEPENDENCIES = Makefile

# For grub-probe.
sbin_UTILITIES += grub-probe
util/grub-probe.c_DEPENDENCIES = grub_probe_init.h
grub_probe_SOURCES = gnulib/progname.c util/grub-probe.c	\
	util/hostdisk.c	util/misc.c util/getroot.c util/mm.c	\
	kern/device.c kern/disk.c kern/err.c kern/misc.c	\
	kern/parser.c kern/partition.c kern/file.c kern/list.c	\
	\
	fs/affs.c fs/cpio.c fs/fat.c fs/ext2.c fs/hfs.c		\
	fs/hfsplus.c fs/iso9660.c fs/udf.c fs/jfs.c fs/minix.c	\
	fs/nilfs2.c fs/ntfs.c fs/ntfscomp.c fs/reiserfs.c	\
	fs/sfs.c fs/ufs.c fs/ufs2.c fs/xfs.c fs/afs.c		\
	fs/afs_be.c fs/befs.c fs/befs_be.c fs/tar.c		\
	\
	partmap/msdos.c partmap/bsdlabel.c partmap/apple.c \
	partmap/sun.c partmap/sunpc.c partmap/gpt.c \
	kern/fs.c kern/env.c fs/fshelp.c			\
	disk/raid.c disk/mdraid_linux.c disk/lvm.c grub_probe_init.c

ifeq ($(enable_grub_fstest), yes)
bin_UTILITIES += grub-fstest
endif

bin_UTILITIES += grub-mkisofs
grub_mkisofs_SOURCES = util/mkisofs/eltorito.c 				\
	util/mkisofs/hash.c util/mkisofs/joliet.c			\
	util/mkisofs/match.c util/mkisofs/mkisofs.c			\
	util/mkisofs/multi.c util/mkisofs/name.c			\
	util/mkisofs/rock.c util/mkisofs/tree.c				\
	util/mkisofs/write.c						\
	\
	gnulib/fnmatch.c gnulib/error.c gnulib/progname.c
grub_mkisofs_CFLAGS = -D_FILE_OFFSET_BITS=64 				\
	-I$(srcdir)/util/mkisofs/include				\
	-Wno-all -Werror $(GNULIB_UTIL_CFLAGS)

# For grub-fstest.
util/grub-fstest.c_DEPENDENCIES = grub_fstest_init.h
grub_fstest_SOURCES = gnulib/progname.c util/grub-fstest.c util/hostfs.c \
	util/misc.c util/mm.c 	\
	kern/file.c kern/device.c kern/disk.c kern/err.c kern/misc.c	\
	disk/host.c disk/loopback.c kern/list.c kern/command.c		\
	lib/arg.c commands/extcmd.c lib/datetime.c lib/misc.c		\
	lib/hexdump.c lib/crc.c commands/blocklist.c commands/ls.c 	\
	\
	fs/affs.c fs/cpio.c fs/fat.c fs/ext2.c fs/hfs.c			\
	fs/hfsplus.c fs/iso9660.c fs/udf.c fs/jfs.c fs/minix.c		\
	fs/nilfs2.c fs/ntfs.c fs/ntfscomp.c fs/reiserfs.c fs/sfs.c	\
	fs/ufs.c fs/ufs2.c fs/xfs.c fs/afs.c fs/afs_be.c fs/befs.c 	\
	fs/befs_be.c fs/tar.c fs/fb.c					\
	\
	kern/partition.c partmap/msdos.c partmap/bsdlabel.c 		\
	partmap/apple.c partmap/sun.c partmap/sunpc.c partmap/gpt.c	\
	kern/fs.c kern/env.c fs/fshelp.c disk/raid.c			\
	disk/raid5_recover.c disk/raid6_recover.c 			\
	disk/mdraid_linux.c disk/dmraid_nvidia.c disk/lvm.c 		\
	grub_fstest_init.c

# For grub-mkfont.
ifeq ($(enable_grub_mkfont), yes)
bin_UTILITIES += grub-mkfont
grub_mkfont_SOURCES = gnulib/progname.c util/grub-mkfont.c util/misc.c \
	util/mm.c kern/misc.c kern/err.c
grub_mkfont_CFLAGS = $(freetype_cflags)
grub_mkfont_LDFLAGS = $(freetype_libs)
endif

# For grub-mkrelpath.
bin_UTILITIES += grub-mkrelpath
grub_mkrelpath_SOURCES = gnulib/progname.c util/grub-mkrelpath.c util/misc.c

bin_UTILITIES += grub-bin2h
grub_bin2h_SOURCES = gnulib/progname.c util/bin2h.c

# For the lexer.
grub_script.yy.c grub_script.yy.h: script/yylex.l
	$(LEX) -o grub_script.yy.c --header-file=grub_script.yy.h $(srcdir)/script/yylex.l
DISTCLEANFILES += grub_script.yy.c grub_script.yy.h

# For grub-script-check.
bin_UTILITIES += grub-script-check
util/grub-script-check.c_DEPENDENCIES = grub_script_check_init.h
grub_script_check_SOURCES = gnulib/progname.c gnulib/getdelim.c gnulib/getline.c \
	util/grub-script-check.c util/misc.c util/mm.c \
	script/main.c script/script.c script/function.c script/lexer.c \
	kern/handler.c kern/err.c kern/parser.c kern/list.c \
	kern/misc.c kern/env.c grub_script_check_init.c grub_script.tab.c \
	grub_script.yy.c
grub_script_check_CFLAGS = $(GNULIB_UTIL_CFLAGS)
MOSTLYCLEANFILES += symlist.c kernel_syms.lst
DEFSYMFILES += kernel_syms.lst

kernel_img_HEADERS += boot.h cache.h device.h disk.h dl.h elf.h elfload.h \
	env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \
	partition.h msdos_partition.h reader.h symbol.h term.h time.h types.h \
	list.h handler.h command.h i18n.h env_private.h libgcc.h

ifneq ($(platform), emu)
kernel_img_HEADERS += machine/memory.h machine/loader.h machine/kernel.h
endif

symlist.c: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h gensymlist.sh
	/bin/sh gensymlist.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1)

kernel_syms.lst: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h genkernsyms.sh
	/bin/sh genkernsyms.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1)

# For the parser.
grub_script.tab.c grub_script.tab.h: script/parser.y
	$(call quiet-command,$(YACC) -d -p grub_script_yy -b grub_script $(srcdir)/script/parser.y,"  YACC  $@")
DISTCLEANFILES += grub_script.tab.c grub_script.tab.h

# For grub-script-check.
grub_script_check_init.lst: geninit.sh $(filter-out grub_script_check_init.c,$(grub_script_check_SOURCES))
	$(call quiet-command,rm -f $@; grep GRUB_MOD_INIT $(filter %.c,$^) /dev/null > $@,"  GEN   $@")
DISTCLEANFILES += grub_script_check_init.lst

grub_script_check_init.h: grub_script_check_init.lst $(filter-out grub_script_check_init.c,$(grub_script_check_SOURCES)) geninitheader.sh
	$(call quiet-command,rm -f $@; sh $(srcdir)/geninitheader.sh $< > $@,"  GEN   $@") 
DISTCLEANFILES += grub_script_check_init.h

grub_script_check_init.c: grub_script_check_init.lst $(filter-out grub_script_check_init.c,$(grub_script_check_SOURCES)) geninit.sh
	$(call quiet-command,rm -f $@; sh $(srcdir)/geninit.sh $< $(filter %.c,$^) > $@,"  GEN   $@")
DISTCLEANFILES += grub_script_check_init.c

# For grub-probe.
grub_probe_init.lst: geninit.sh $(filter-out grub_probe_init.c,$(grub_probe_SOURCES))
	$(call quiet-command,rm -f $@; grep GRUB_MOD_INIT $(filter %.c,$^) /dev/null > $@,"  GEN   $@")
DISTCLEANFILES += grub_probe_init.lst

grub_probe_init.h: grub_probe_init.lst $(filter-out grub_probe_init.c,$(grub_probe_SOURCES)) geninitheader.sh
	$(call quiet-command,rm -f $@; sh $(srcdir)/geninitheader.sh $< > $@,"  GEN   $@")
DISTCLEANFILES += grub_probe_init.h

grub_probe_init.c: grub_probe_init.lst $(filter-out grub_probe_init.c,$(grub_probe_SOURCES)) geninit.sh grub_probe_init.h
	$(call quiet-command,rm -f $@; sh $(srcdir)/geninit.sh $< $(filter %.c,$^) > $@,"  GEN   $@")
DISTCLEANFILES += grub_probe_init.c

# For grub-setup.
grub_setup_init.lst: geninit.sh $(filter-out grub_setup_init.c,$(grub_setup_SOURCES))
	$(call quiet-command,rm -f $@; grep GRUB_MOD_INIT $(filter %.c,$^) /dev/null > $@,"  GEN   $@")
DISTCLEANFILES += grub_setup_init.lst

grub_setup_init.h: grub_setup_init.lst $(filter-out grub_setup_init.c,$(grub_setup_SOURCES)) geninitheader.sh
	$(call quiet-command,rm -f $@; sh $(srcdir)/geninitheader.sh $< > $@,"  GEN   $@")
DISTCLEANFILES += grub_setup_init.h

grub_setup_init.c: grub_setup_init.lst $(filter-out grub_setup_init.c,$(grub_setup_SOURCES)) geninit.sh grub_setup_init.h
	$(call quiet-command,rm -f $@; sh $(srcdir)/geninit.sh $< $(filter %.c,$^) > $@,"  GEN   $@")
DISTCLEANFILES += grub_setup_init.c

# For grub-fstest.
grub_fstest_init.lst: geninit.sh $(filter-out grub_fstest_init.c,$(grub_fstest_SOURCES))
	$(call quiet-command,rm -f $@; grep GRUB_MOD_INIT $(filter %.c,$^) /dev/null > $@,"  GEN   $@")
DISTCLEANFILES += grub_fstest_init.lst

grub_fstest_init.h: grub_fstest_init.lst $(filter-out grub_fstest_init.c,$(grub_fstest_SOURCES)) geninitheader.sh
	$(call quiet-command,rm -f $@; sh $(srcdir)/geninitheader.sh $< > $@,"  GEN   $@")
DISTCLEANFILES += grub_fstest_init.h

grub_fstest_init.c: grub_fstest_init.lst $(filter-out grub_fstest_init.c,$(grub_fstest_SOURCES)) geninit.sh grub_fstest_init.h
	$(call quiet-command,rm -f $@; sh $(srcdir)/geninit.sh $< $(filter %.c,$^) > $@,"  GEN   $@")
DISTCLEANFILES += grub_fstest_init.c

# for grub-editenv
bin_UTILITIES += grub-editenv
grub_editenv_SOURCES = gnulib/progname.c util/grub-editenv.c lib/envblk.c util/misc.c util/mm.c kern/misc.c kern/err.c
CLEANFILES += grub-editenv

# for grub-mkpasswd
#bin_UTILITIES += grub-mkpasswd
grub_mkpasswd_SOURCES = gnulib/progname.c util/grub-mkpasswd.c \
	lib/md5_password.c util/misc.c kern/misc.c kern/err.c
CLEANFILES += grub-mkpasswd

# Needed for genmk.rb to work
ifeq (0,1)
bin_UTILITIES += grub-macho2img grub-pe2elf
endif

grub_pe2elf_SOURCES = gnulib/progname.c util/grub-pe2elf.c util/misc.c
CLEANFILES += grub-pe2elf

# grub-mkmod
bin_UTILITIES += grub-mkmod
grub_mkmod_SOURCES = gnulib/progname.c util/grub-mkmod.c util/misc.c \
	util/obj.c util/obj_pe.c util/obj_elf.c util/obj_macho.c kern/list.c
CLEANFILES += grub-mkmod

# grub-mkimg
bin_UTILITIES += grub-mkimg
grub_mkimg_SOURCES = gnulib/progname.c util/grub-mkimg.c \
	util/misc.c util/obj.c util/obj_pe.c util/obj_elf.c util/obj_macho.c \
	kern/list.c
CLEANFILES += grub-mkimg

# grub-symdb
bin_UTILITIES += grub-symdb
grub_symdb_SOURCES = gnulib/progname.c util/grub-symdb.c util/obj.c \
	util/misc.c kern/list.c
CLEANFILES += grub-symdb

# grub-objdump
bin_UTILITIES += grub-objdump
grub_objdump_SOURCES = gnulib/progname.c util/grub-objdump.c util/obj.c \
	util/misc.c util/obj_dump.c kern/list.c
CLEANFILES += grub-objdump

# grub_macho2img assumes a lot about source file.
# So installing it definitively is useless
# But adding to bin_UTILITIES is needed for
# genmk.rb to work
grub_macho2img_SOURCES = util/grub-macho2img.c
CLEANFILES += grub-macho2img

# For grub-mkconfig
grub-mkconfig: util/grub-mkconfig.in config.status
	./config.status --file=$@:$<
	chmod +x $@
sbin_SCRIPTS += grub-mkconfig
CLEANFILES += grub-mkconfig

grub-mkconfig_lib: util/grub-mkconfig_lib.in config.status
	./config.status --file=$@:$<
	chmod +x $@
lib_SCRIPTS += grub-mkconfig_lib
CLEANFILES += grub-mkconfig_lib

update-grub_lib: util/update-grub_lib.in config.status
	./config.status --file=$@:$<
	chmod +x $@
lib_SCRIPTS += update-grub_lib
CLEANFILES += update-grub_lib

grub-gettext_lib: util/grub-gettext_lib.in config.status
	./config.status --file=$@:$<
	chmod +x $@
lib_DATA += grub-gettext_lib
CLEANFILES += grub-gettext_lib

%: util/grub.d/%.in config.status
	./config.status --file=$@:$<
	chmod +x $@
grub-mkconfig_SCRIPTS = 00_header 30_os-prober 40_custom
ifneq (, $(host_kernel))
grub-mkconfig_SCRIPTS += 10_$(host_kernel)
endif

CLEANFILES += $(grub-mkconfig_SCRIPTS)

grub-mkconfig_DATA += util/grub.d/README

# For grub-set-default.
grub-set-default: util/grub-set-default.in config.status
	./config.status --file=$@:$<
	chmod +x $@
sbin_SCRIPTS += grub-set-default
CLEANFILES += grub-set-default

# For grub-reboot.
grub-reboot: util/grub-reboot.in config.status
	./config.status --file=$@:$<
	chmod +x $@
sbin_SCRIPTS += grub-reboot
CLEANFILES += grub-reboot

# For grub-adduser.
grub-adduser: util/grub-adduser.in config.status
	./config.status --file=$@:$<
	chmod +x $@
sbin_SCRIPTS += grub-adduser
CLEANFILES += grub-adduser

# For grub-deluser.
grub-deluser: util/grub-deluser.in config.status
	./config.status --file=$@:$<
	chmod +x $@
sbin_SCRIPTS += grub-deluser
CLEANFILES += grub-deluser

# Filing systems.
pkglib_MODULES += fshelp.mod fat.mod ufs1.mod ufs2.mod ext2.mod ntfs.mod \
	ntfscomp.mod minix.mod hfs.mod jfs.mod iso9660.mod xfs.mod	\
	affs.mod sfs.mod hfsplus.mod reiserfs.mod cpio.mod tar.mod	\
	udf.mod	afs.mod afs_be.mod befs.mod befs_be.mod fb.mod

# For fshelp.mod.
fshelp_mod_SOURCES = fs/fshelp.c
fshelp_mod_CFLAGS = $(COMMON_CFLAGS)
fshelp_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For fat.mod.
fat_mod_SOURCES = fs/fat.c
fat_mod_CFLAGS = $(COMMON_CFLAGS)
fat_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For ufs1.mod.
ufs1_mod_SOURCES = fs/ufs.c
ufs1_mod_CFLAGS = $(COMMON_CFLAGS)
ufs1_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For ufs2.mod.
ufs2_mod_SOURCES = fs/ufs2.c
ufs2_mod_CFLAGS = $(COMMON_CFLAGS)
ufs2_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For ext2.mod.
ext2_mod_SOURCES = fs/ext2.c
ext2_mod_CFLAGS = $(COMMON_CFLAGS)
ext2_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For ntfs.mod.
ntfs_mod_SOURCES = fs/ntfs.c
ntfs_mod_CFLAGS = $(COMMON_CFLAGS)
ntfs_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For ntfscomp.mod.
ntfscomp_mod_SOURCES = fs/ntfscomp.c
ntfscomp_mod_CFLAGS = $(COMMON_CFLAGS)
ntfscomp_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For minix.mod.
minix_mod_SOURCES = fs/minix.c
minix_mod_CFLAGS = $(COMMON_CFLAGS)
minix_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For nilfs2.mod.
pkglib_MODULES += nilfs2.mod
nilfs2_mod_SOURCES = fs/nilfs2.c
nilfs2_mod_CFLAGS = $(COMMON_CFLAGS)
nilfs2_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For hfs.mod.
hfs_mod_SOURCES = fs/hfs.c
hfs_mod_CFLAGS = $(COMMON_CFLAGS)
hfs_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For jfs.mod.
jfs_mod_SOURCES = fs/jfs.c
jfs_mod_CFLAGS = $(COMMON_CFLAGS)
jfs_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For iso9660.mod.
iso9660_mod_SOURCES = fs/iso9660.c
iso9660_mod_CFLAGS = $(COMMON_CFLAGS)
iso9660_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For xfs.mod.
xfs_mod_SOURCES = fs/xfs.c
xfs_mod_CFLAGS = $(COMMON_CFLAGS)
xfs_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For affs.mod.
affs_mod_SOURCES = fs/affs.c
affs_mod_CFLAGS = $(COMMON_CFLAGS)
affs_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For sfs.mod.
sfs_mod_SOURCES = fs/sfs.c
sfs_mod_CFLAGS = $(COMMON_CFLAGS)
sfs_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For hfsplus.mod.
hfsplus_mod_SOURCES = fs/hfsplus.c
hfsplus_mod_CFLAGS = $(COMMON_CFLAGS)
hfsplus_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For reiserfs.mod.
reiserfs_mod_SOURCES = fs/reiserfs.c
reiserfs_mod_CFLAGS = $(COMMON_CFLAGS)
reiserfs_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For cpio.mod.
cpio_mod_SOURCES = fs/cpio.c
cpio_mod_CFLAGS = $(COMMON_CFLAGS)
cpio_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For tar.mod.
tar_mod_SOURCES = fs/tar.c
tar_mod_CFLAGS = $(COMMON_CFLAGS)
tar_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For udf.mod.
udf_mod_SOURCES = fs/udf.c
udf_mod_CFLAGS = $(COMMON_CFLAGS)
udf_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For afs.mod.
afs_mod_SOURCES = fs/afs.c
afs_mod_CFLAGS = $(COMMON_CFLAGS)
afs_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For afs_be.mod.
afs_be_mod_SOURCES = fs/afs_be.c
afs_be_mod_CFLAGS = $(COMMON_CFLAGS)
afs_be_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For befs.mod.
befs_mod_SOURCES = fs/befs.c
befs_mod_CFLAGS = $(COMMON_CFLAGS)
befs_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For befs_be.mod.
befs_be_mod_SOURCES = fs/befs_be.c
befs_be_mod_CFLAGS = $(COMMON_CFLAGS)
befs_be_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For fb.mod.
fb_mod_SOURCES = fs/fb.c
fb_mod_CFLAGS = $(COMMON_CFLAGS)
fb_mod_LDFLAGS = $(COMMON_LDFLAGS)

# Partition maps.

pkglib_MODULES += part_amiga.mod
part_amiga_mod_SOURCES = partmap/amiga.c
part_amiga_mod_CFLAGS = $(COMMON_CFLAGS)
part_amiga_mod_LDFLAGS = $(COMMON_LDFLAGS)

pkglib_MODULES += part_apple.mod
part_apple_mod_SOURCES = partmap/apple.c
part_apple_mod_CFLAGS = $(COMMON_CFLAGS)
part_apple_mod_LDFLAGS = $(COMMON_LDFLAGS)

pkglib_MODULES += part_msdos.mod
part_msdos_mod_SOURCES = partmap/msdos.c
part_msdos_mod_CFLAGS = $(COMMON_CFLAGS)
part_msdos_mod_LDFLAGS = $(COMMON_LDFLAGS)

pkglib_MODULES += part_sun.mod
part_sun_mod_SOURCES = partmap/sun.c
part_sun_mod_CFLAGS = $(COMMON_CFLAGS)
part_sun_mod_LDFLAGS = $(COMMON_LDFLAGS)

pkglib_MODULES += part_acorn.mod
part_acorn_mod_SOURCES = partmap/acorn.c
part_acorn_mod_CFLAGS = $(COMMON_CFLAGS)
part_acorn_mod_LDFLAGS = $(COMMON_LDFLAGS)

pkglib_MODULES += part_gpt.mod
part_gpt_mod_SOURCES = partmap/gpt.c
part_gpt_mod_CFLAGS = $(COMMON_CFLAGS)
part_gpt_mod_LDFLAGS = $(COMMON_LDFLAGS)

pkglib_MODULES += part_bsd.mod
part_bsd_mod_SOURCES = partmap/bsdlabel.c
part_bsd_mod_CFLAGS = $(COMMON_CFLAGS)
part_bsd_mod_LDFLAGS = $(COMMON_LDFLAGS)

pkglib_MODULES += part_sunpc.mod
part_sunpc_mod_SOURCES = partmap/sunpc.c
part_sunpc_mod_CFLAGS = $(COMMON_CFLAGS)
part_sunpc_mod_LDFLAGS = $(COMMON_LDFLAGS)

# Special disk structures and generic drivers

pkglib_MODULES += raid.mod raid5rec.mod raid6rec.mod mdraid.mod dm_nv.mod \
	lvm.mod scsi.mod

# For raid.mod
raid_mod_SOURCES = disk/raid.c
raid_mod_CFLAGS = $(COMMON_CFLAGS)
raid_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For raid5rec.mod
raid5rec_mod_SOURCES = disk/raid5_recover.c
raid5rec_mod_CFLAGS = $(COMMON_CFLAGS)
raid5rec_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For raid6rec.mod
raid6rec_mod_SOURCES = disk/raid6_recover.c
raid6rec_mod_CFLAGS = $(COMMON_CFLAGS)
raid6rec_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For mdraid.mod
mdraid_mod_SOURCES = disk/mdraid_linux.c
mdraid_mod_CFLAGS = $(COMMON_CFLAGS)
mdraid_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For dm_nv.mod
dm_nv_mod_SOURCES = disk/dmraid_nvidia.c
dm_nv_mod_CFLAGS = $(COMMON_CFLAGS)
dm_nv_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For lvm.mod
lvm_mod_SOURCES = disk/lvm.c
lvm_mod_CFLAGS = $(COMMON_CFLAGS)
lvm_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For scsi.mod
scsi_mod_SOURCES = disk/scsi.c
scsi_mod_CFLAGS = $(COMMON_CFLAGS)
scsi_mod_LDFLAGS = $(COMMON_LDFLAGS)

# Commands.
pkglib_MODULES += minicmd.mod extcmd.mod hello.mod handler.mod	\
	ls.mod cmp.mod cat.mod help.mod search.mod loopback.mod	\
	configfile.mod echo.mod		\
	terminfo.mod test.mod blocklist.mod hexdump.mod		\
	read.mod sleep.mod loadenv.mod crc.mod parttool.mod	\
	msdospart.mod memrw.mod normal.mod sh.mod 		\
	gptsync.mod true.mod probe.mod password.mod		\
	keystatus.mod lib.mod emenu.mod widget.mod txtrgn.mod	\
	gfxrgn.mod coreui.mod loadcfg.mod nmenu.mod

# For password.mod.
password_mod_SOURCES = commands/password.c
password_mod_CFLAGS = $(COMMON_CFLAGS)
password_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For gptsync.mod.
gptsync_mod_SOURCES = commands/gptsync.c
gptsync_mod_CFLAGS = $(COMMON_CFLAGS)
gptsync_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For minicmd.mod.
minicmd_mod_SOURCES = commands/minicmd.c
minicmd_mod_CFLAGS = $(COMMON_CFLAGS)
minicmd_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For extcmd.mod.
extcmd_mod_SOURCES = commands/extcmd.c lib/arg.c
extcmd_mod_CFLAGS = $(COMMON_CFLAGS)
extcmd_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For hello.mod.
hello_mod_SOURCES = hello/hello.c
hello_mod_CFLAGS = $(COMMON_CFLAGS)
hello_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For lib.mod.
lib_mod_SOURCES = lib/tree.c lib/uitree.c lib/auth.c lib/print_ucs4.c \
	lib/datetime.c lib/completion.c lib/misc.c lib/crc.c \
	lib/hexdump.c lib/getline.c lib/history.c lib/menu_entry.c \
	lib/autolist.c lib/context.c
lib_mod_CFLAGS = $(COMMON_CFLAGS)
lib_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For nmenu.mod.
nmenu_mod_SOURCES = menu/normal/main.c menu/normal/color.c menu/normal/menu.c \
	menu/normal/menu_entry.c menu/normal/menu_text.c menu/normal/cmdline.c 
nmenu_mod_CFLAGS = $(COMMON_CFLAGS)
nmenu_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For emenu.mod.
emenu_mod_SOURCES = menu/ext/main.c
emenu_mod_CFLAGS = $(COMMON_CFLAGS)
emenu_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For widget.mod.
widget_mod_SOURCES = menu/ext/region.c menu/ext/widget.c menu/ext/data_type.c \
	menu/ext/dialog.c
widget_mod_CFLAGS = $(COMMON_CFLAGS)
widget_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For txtrgn.mod
txtrgn_mod_SOURCES = menu/ext/text_region.c
txtrgn_mod_CFLAGS = $(COMMON_CFLAGS)
txtrgn_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For gfxrgn.mod
gfxrgn_mod_SOURCES = menu/ext/gfx_region.c
gfxrgn_mod_CFLAGS = $(COMMON_CFLAGS)
gfxrgn_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For menucmd.mod
menucmd_mod_SOURCES = commands/menucmd.c
menucmd_mod_CFLAGS = $(COMMON_CFLAGS)
menucmd_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For loadcfg.mod
loadcfg_mod_SOURCES = commands/loadcfg.c
loadcfg_mod_CFLAGS = $(COMMON_CFLAGS)
loadcfg_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For coreui.mod
coreui_mod_SOURCES = ui/coreui.c
coreui_mod_CFLAGS = $(COMMON_CFLAGS)
coreui_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For gfxmenu.mod.
pkglib_MODULES += gfxmenu.mod
gfxmenu_mod_SOURCES = \
	gfxmenu/gfxmenu.c \
	gfxmenu/model.c \
	gfxmenu/view.c \
	gfxmenu/icon_manager.c \
	gfxmenu/theme_loader.c \
	gfxmenu/widget-box.c \
	gfxmenu/gui_canvas.c \
	gfxmenu/gui_circular_progress.c \
	gfxmenu/gui_box.c \
	gfxmenu/gui_label.c \
	gfxmenu/gui_list.c \
	gfxmenu/gui_image.c \
	gfxmenu/gui_progress_bar.c \
	gfxmenu/gui_util.c \
	gfxmenu/gui_string_util.c \
	gfxmenu/named_colors.c
gfxmenu_mod_CFLAGS = $(COMMON_CFLAGS)
gfxmenu_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For parttool.mod.
parttool_mod_SOURCES = commands/parttool.c
parttool_mod_CFLAGS = $(COMMON_CFLAGS)
parttool_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For msdospart.mod.
msdospart_mod_SOURCES = parttool/msdospart.c
msdospart_mod_CFLAGS = $(COMMON_CFLAGS)
msdospart_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For handler.mod.
handler_mod_SOURCES = commands/handler.c
handler_mod_CFLAGS = $(COMMON_CFLAGS)
handler_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For ls.mod.
ls_mod_SOURCES = commands/ls.c
ls_mod_CFLAGS = $(COMMON_CFLAGS)
ls_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For cmp.mod.
cmp_mod_SOURCES = commands/cmp.c
cmp_mod_CFLAGS = $(COMMON_CFLAGS)
cmp_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For cat.mod.
cat_mod_SOURCES = commands/cat.c
cat_mod_CFLAGS = $(COMMON_CFLAGS)
cat_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For echo.mod
echo_mod_SOURCES = commands/echo.c
echo_mod_CFLAGS = $(COMMON_CFLAGS)
echo_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For help.mod.
help_mod_SOURCES = commands/help.c
help_mod_CFLAGS = $(COMMON_CFLAGS)
help_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For search.mod.
search_mod_SOURCES = commands/search_wrap.c
search_mod_CFLAGS = $(COMMON_CFLAGS)
search_mod_LDFLAGS = $(COMMON_LDFLAGS)

pkglib_MODULES += search_fs_file.mod search_fs_uuid.mod search_label.mod

# For search.mod.
search_fs_file_mod_SOURCES = commands/search_file.c
search_fs_file_mod_CFLAGS = $(COMMON_CFLAGS)
search_fs_file_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For search.mod.
search_label_mod_SOURCES = commands/search_label.c
search_label_mod_CFLAGS = $(COMMON_CFLAGS)
search_label_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For search.mod.
search_fs_uuid_mod_SOURCES = commands/search_uuid.c
search_fs_uuid_mod_CFLAGS = $(COMMON_CFLAGS)
search_fs_uuid_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For test.mod.
test_mod_SOURCES = commands/test.c
test_mod_CFLAGS = $(COMMON_CFLAGS)
test_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For loopback.mod
loopback_mod_SOURCES = disk/loopback.c
loopback_mod_CFLAGS = $(COMMON_CFLAGS)
loopback_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For configfile.mod
configfile_mod_SOURCES = commands/configfile.c
configfile_mod_CFLAGS = $(COMMON_CFLAGS)
configfile_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For terminfo.mod.
terminfo_mod_SOURCES = term/terminfo.c term/tparm.c
terminfo_mod_CFLAGS = $(COMMON_CFLAGS)
terminfo_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For blocklist.mod.
blocklist_mod_SOURCES = commands/blocklist.c
blocklist_mod_CFLAGS = $(COMMON_CFLAGS)
blocklist_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For hexdump.mod.
hexdump_mod_SOURCES = commands/hexdump.c
hexdump_mod_CFLAGS = $(COMMON_CFLAGS)
hexdump_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For read.mod.
read_mod_SOURCES = commands/read.c
read_mod_CFLAGS = $(COMMON_CFLAGS)
read_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For sleep.mod.
sleep_mod_SOURCES = commands/sleep.c
sleep_mod_CFLAGS = $(COMMON_CFLAGS)
sleep_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For loadenv.mod.
loadenv_mod_SOURCES = commands/loadenv.c lib/envblk.c
ifeq ($(platform), emu)
loadenv_mod_CFLAGS = $(TARGET_CPPFLAGS) $(TARGET_CFLAGS)
else
loadenv_mod_CFLAGS = $(COMMON_CFLAGS)
endif
loadenv_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For crc.mod.
crc_mod_SOURCES = commands/crc.c
crc_mod_CFLAGS = $(COMMON_CFLAGS)
crc_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For memrw.mod.
memrw_mod_SOURCES = commands/memrw.c
memrw_mod_CFLAGS = $(COMMON_CFLAGS)
memrw_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For true.mod
true_mod_SOURCES = commands/true.c
true_mod_CFLAGS = $(COMMON_CFLAGS)
true_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For probe.mod.
probe_mod_SOURCES = commands/probe.c
probe_mod_CFLAGS = $(COMMON_CFLAGS)
probe_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For keystatus.mod.
keystatus_mod_SOURCES = commands/keystatus.c
keystatus_mod_CFLAGS = $(COMMON_CFLAGS)
keystatus_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For normal.mod.
normal_mod_SOURCES = normal/main.c normal/dyncmd.c normal/autofs.c \
	normal/handler.c normal/crypto.c normal/term.c
normal_mod_CFLAGS = $(COMMON_CFLAGS)
normal_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For sh.mod.
sh_mod_SOURCES = script/main.c script/script.c script/execute.c \
	script/function.c script/lexer.c grub_script.tab.c grub_script.yy.c
sh_mod_CFLAGS = $(COMMON_CFLAGS) $(POSIX_CFLAGS) -Wno-error
sh_mod_LDFLAGS = $(COMMON_LDFLAGS)

ifneq (, $(FONT_SOURCE))
font/font.c_DEPENDENCIES = ascii.h
endif

# Common Video Subsystem specific modules.
# On Yeeloong it's part of kernel
ifneq ($(platform), yeeloong)

# For video.mod.
pkglib_MODULES += video.mod
video_mod_SOURCES = video/video.c
video_mod_CFLAGS = $(COMMON_CFLAGS)
video_mod_LDFLAGS = $(COMMON_LDFLAGS)

pkglib_MODULES += video_fb.mod
video_fb_mod_SOURCES = video/fb/video_fb.c video/fb/fbblit.c \
		  video/fb/fbfill.c video/fb/fbutil.c
video_fb_mod_CFLAGS = $(COMMON_CFLAGS)
video_fb_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For bitmap.mod
pkglib_MODULES += bitmap.mod
bitmap_mod_SOURCES = video/bitmap.c
bitmap_mod_CFLAGS = $(COMMON_CFLAGS)
bitmap_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For bitmap_scale.mod
pkglib_MODULES += bitmap_scale.mod
bitmap_scale_mod_SOURCES = video/bitmap_scale.c
bitmap_scale_mod_CFLAGS = $(COMMON_CFLAGS)
bitmap_scale_mod_LDFLAGS = $(COMMON_LDFLAGS)

pkglib_MODULES += font.mod
font_mod_SOURCES = font/font_cmd.c font/font.c
font_mod_CFLAGS = $(COMMON_CFLAGS)
font_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For gfxterm.mod.
pkglib_MODULES += gfxterm.mod
gfxterm_mod_SOURCES = term/gfxterm.c
gfxterm_mod_CFLAGS = $(COMMON_CFLAGS)
gfxterm_mod_LDFLAGS = $(COMMON_LDFLAGS)

endif

# For videotest.mod.
pkglib_MODULES += videotest.mod
videotest_mod_SOURCES = commands/videotest.c
videotest_mod_CFLAGS = $(COMMON_CFLAGS)
videotest_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For tga.mod
pkglib_MODULES += tga.mod
tga_mod_SOURCES = video/readers/tga.c
tga_mod_CFLAGS = $(COMMON_CFLAGS)
tga_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For jpeg.mod.
pkglib_MODULES += jpeg.mod
jpeg_mod_SOURCES = video/readers/jpeg.c
jpeg_mod_CFLAGS = $(COMMON_CFLAGS)
jpeg_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For png.mod.
pkglib_MODULES += png.mod
png_mod_SOURCES = video/readers/png.c
png_mod_CFLAGS = $(COMMON_CFLAGS)
png_mod_LDFLAGS = $(COMMON_LDFLAGS)


# Misc.
pkglib_MODULES += gzio.mod elf.mod

# For elf.mod.
elf_mod_SOURCES = kern/elf.c
elf_mod_CFLAGS = $(COMMON_CFLAGS)
elf_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For gzio.mod.
gzio_mod_SOURCES = io/gzio.c
gzio_mod_CFLAGS = $(COMMON_CFLAGS)
gzio_mod_LDFLAGS = $(COMMON_LDFLAGS)

# On Yeeloong it's part of kernel
ifneq ($(platform), yeeloong)
# For bufio.mod.
pkglib_MODULES += bufio.mod
bufio_mod_SOURCES = io/bufio.c
bufio_mod_CFLAGS = $(COMMON_CFLAGS)
bufio_mod_LDFLAGS = $(COMMON_LDFLAGS)
endif

# For gettext.mod.
pkglib_MODULES += gettext.mod
gettext_mod_SOURCES = gettext/gettext.c
gettext_mod_CFLAGS = $(COMMON_CFLAGS)
gettext_mod_LDFLAGS = $(COMMON_LDFLAGS)

# Misc.
pkglib_MODULES += xnu_uuid.mod

# For elf.mod.
xnu_uuid_mod_SOURCES = commands/xnu_uuid.c
xnu_uuid_mod_CFLAGS = $(COMMON_CFLAGS)
xnu_uuid_mod_LDFLAGS = $(COMMON_LDFLAGS)

pkglib_MODULES += trig.mod
trig_mod_SOURCES = trigtables.c
trig_mod_CFLAGS = $(COMMON_CFLAGS)
trig_mod_LDFLAGS = $(COMMON_LDFLAGS)

trigtables.c: gentrigtables
	./gentrigtables > $@
DISTCLEANFILES += trigtables.c
gentrigtables: gentrigtables.c
	$(CC) -o $@ $^ $(CPPFLAGS) -lm
DISTCLEANFILES += gentrigtables

pkglib_MODULES += setjmp.mod
setjmp_mod_SOURCES = lib/$(target_cpu)/setjmp.S
setjmp_mod_ASFLAGS = $(COMMON_ASFLAGS)
setjmp_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For lua.mod
pkglib_MODULES += lua.mod
lua_mod_SOURCES = script/lua/grub_main.c script/lua/grub_lib.c \
	script/lua/lapi.c script/lua/lcode.c script/lua/ldebug.c \
	script/lua/ldo.c script/lua/ldump.c script/lua/lfunc.c \
	script/lua/lgc.c script/lua/llex.c script/lua/lmem.c \
	script/lua/lobject.c script/lua/lopcodes.c script/lua/lparser.c \
	script/lua/lstate.c script/lua/lstring.c script/lua/ltable.c \
	script/lua/ltm.c script/lua/lundump.c script/lua/lvm.c \
	script/lua/lzio.c script/lua/lauxlib.c script/lua/lbaselib.c \
	script/lua/linit.c script/lua/ltablib.c script/lua/lstrlib.c
lua_mod_CFLAGS = $(COMMON_CFLAGS)
lua_mod_LDFLAGS = $(COMMON_LDFLAGS)

# Extra libraries for lua
# script/lua/lmathlib.c script/lua/loslib.c script/lua/liolib.c
# script/lua/ldblib.c script/lua/loadlib.c

pkglib_MODULES += charset.mod
charset_mod_SOURCES = lib/charset.c
charset_mod_CFLAGS = $(COMMON_CFLAGS)
charset_mod_LDFLAGS = $(COMMON_LDFLAGS)

pkglib_MODULES += regexp.mod
regexp_mod_SOURCES = gnulib/regex.c commands/regexp.c
regexp_mod_CFLAGS = $(COMMON_CFLAGS) $(GNULIB_CFLAGS)
regexp_mod_LDFLAGS = $(COMMON_LDFLAGS)

pkglib_MODULES += terminal.mod
terminal_mod_SOURCES = commands/terminal.c
terminal_mod_CFLAGS = $(COMMON_CFLAGS)
terminal_mod_LDFLAGS = $(COMMON_LDFLAGS)

pkglib_MODULES += crypto.mod
crypto_mod_SOURCES = lib/crypto.c
crypto_mod_CFLAGS = $(COMMON_CFLAGS)
crypto_mod_LDFLAGS = $(COMMON_LDFLAGS)

pkglib_MODULES += hashsum.mod
hashsum_mod_SOURCES = commands/hashsum.c
hashsum_mod_CFLAGS = $(COMMON_CFLAGS)
hashsum_mod_LDFLAGS = $(COMMON_LDFLAGS)

pkglib_MODULES += pbkdf2.mod
pbkdf2_mod_SOURCES = lib/pbkdf2.c
pbkdf2_mod_CFLAGS = $(COMMON_CFLAGS)
pbkdf2_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For password_pbkdf2.mod.
pkglib_MODULES += password_pbkdf2.mod
password_pbkdf2_mod_SOURCES = commands/password_pbkdf2.c
password_pbkdf2_mod_CFLAGS = $(COMMON_CFLAGS)
password_pbkdf2_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For memdisk.mod.
pkglib_MODULES += memdisk.mod
memdisk_mod_SOURCES = disk/memdisk.c
memdisk_mod_CFLAGS = $(COMMON_CFLAGS)
memdisk_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For reboot.mod.
pkglib_MODULES += reboot.mod
reboot_mod_SOURCES = commands/reboot.c
reboot_mod_CFLAGS = $(COMMON_CFLAGS)
reboot_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For date.mod
pkglib_MODULES += date.mod
date_mod_SOURCES = commands/date.c
date_mod_CFLAGS = $(COMMON_CFLAGS)
date_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For datehook.mod
pkglib_MODULES += datehook.mod
datehook_mod_SOURCES = hook/datehook.c
datehook_mod_CFLAGS = $(COMMON_CFLAGS)
datehook_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For time.mod
pkglib_MODULES += time.mod
time_mod_SOURCES = commands/time.c
time_mod_CFLAGS = $(COMMON_CFLAGS)
time_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For lsmmap.mod
pkglib_MODULES += lsmmap.mod
lsmmap_mod_SOURCES = commands/lsmmap.c
lsmmap_mod_CFLAGS = $(COMMON_CFLAGS)
lsmmap_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For boot.mod.
pkglib_MODULES += boot.mod
boot_mod_SOURCES = commands/boot.c lib/i386/pc/biosnum.c
boot_mod_CFLAGS = $(COMMON_CFLAGS)
boot_mod_LDFLAGS = $(COMMON_LDFLAGS)

# For dd.mod.
pkglib_MODULES += dd.mod
dd_mod_SOURCES = commands/dd.c
dd_mod_CFLAGS = $(COMMON_CFLAGS)
dd_mod_LDFLAGS = $(COMMON_LDFLAGS)

bin_UTILITIES += grub-mkpasswd-pbkdf2
grub_mkpasswd_pbkdf2_SOURCES = gnulib/progname.c gnulib/getdelim.c gnulib/getline.c util/grub-mkpasswd-pbkdf2.c lib/crypto.c lib/libgcrypt-grub/cipher/sha512.c lib/pbkdf2.c util/misc.c util/mm.c kern/err.c
grub_mkpasswd_pbkdf2_CFLAGS += -Wno-error -I$(srcdir)/lib/libgcrypt_wrap -DGRUB_MKPASSWD=1

include $(srcdir)/conf/gcry.mk
